<template>
  <el-card>
    <el-container>
      <el-header>
        <h2 style="text-align: center">{{ companyData.name }}</h2>
      </el-header>
      <el-main>
        <span>企业名称： <el-input v-model="companyData.name" class="company"></el-input></span>
        <span>企业地址： <el-input v-model="companyData.address" class="company"></el-input></span>
        <span>所在楼栋：
        <el-select v-model="companyData.buildingIndex" class="company" placeholder="请选择">
            <el-option
                v-for="(value, key) in options"
                :key="key"
                :label="value"
                :value="key">
        </el-option>
      </el-select>
      </span>

        <span>认证类型：
        <el-select v-model="companyData.certificationType" class="company" multiple>
          <el-option label="知识产权贯标" value="知识产权贯标"></el-option>
          <el-option label="质量体系认证" value="质量体系认证"></el-option>
          <el-option label="CNSA认证" value="CNSA认证"></el-option>
          <el-option label="未认证" value="未认证"></el-option>
        </el-select>
      </span>
        <span>企业类型：
        <el-select v-model="companyData.type" class="company">
          <el-option label="高新技术企业" value="高新技术企业"></el-option>
          <el-option label="科技型中小企业" value="科技型中小企业"></el-option>
          <el-option label="中小微企业" value="中小微企业"></el-option>
          <el-option label="大规模企业" value="大规模企业"></el-option>
        </el-select>
      </span>
        <span>电话号码： <el-input v-model="companyData.phone" class="company"></el-input></span>
        <span>联系人： <el-input v-model="companyData.contactPerson" class="company"
                             style="margin-left: 16px"></el-input></span>
        <span>业务类型：
             <el-select v-model="companyData.businessType" class="company" placeholder="请选择" value-key="name">
                <el-option
                    v-for="(value, key) in businessName"
                    :key="key"
                    :label="value.name"
                    :value="value.name">
                </el-option>
              </el-select>
      </span>
        <span>员工数量： <el-input v-model="companyData.employeeCount	" class="company"></el-input></span>
        <span v-if="companyData.timestamp">入驻时间： <el-input v-model="companyData.timestamp.timeString" :readonly="true"
                                                           class="company"></el-input></span>
        <br>
        <p style="text-align: right">
          <el-button plain type="primary" @click="modifyCompanyInformation">修改企业</el-button>
          <el-button plain type="danger" @click="deleteCompany">删除企业</el-button>
        </p>
      </el-main>
    </el-container>
  </el-card>

</template>

<script>
import buildingIndex from "../../../common/buildingIndex";
import {deleteCompany, QueryCompany, updateCompany} from "../../../network/companyApi";
import {findAllBusiness} from "../../../network/businessTypeApi";

export default {
  name: "companyInformation",
  data() {
    return {
      //公司数据
      companyData: [],
      options: buildingIndex,
      businessName: ""
    }
  },

  mounted() {
    this.inquiryCompany()
    findAllBusiness({showMessage: 1}).then(res => {
      this.businessName = res.data
    })
  },
  methods: {
    //查询公司
    inquiryCompany() {
      let page = {condition: {uuid: this.uuid}}
      QueryCompany(page).then(res => {
        this.companyData = res.data.records[0]
      })
    },
    //修改公司
    modifyCompanyInformation() {

      this.$confirm('确定修改公司数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateCompany(this.companyData).then(res => {
          if (res.code === 2000) {
            this.inquiryCompany()
          }
          if (res.code !== 2000) {
            this.$message({
              message: res.message,
              type: "error"
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消修改'
        })
      })


    },
    //删除公司
    deleteCompany() {
      this.$confirm('此操作将永久删除该公司所有数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteCompany(this.companyData.uuid).then(res => {
          if (res.code === 2000) {
            this.$router.push({
              path: '/newCompany',
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })

    }

  },
  props: ['uuid']
}
</script>

<style scoped>
.company {
  width: 200px;
  margin-top: 1%;
  margin-right: 5.7%;
}
</style>